/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package alcatelparser.modules.io;

import alcatelparser.modules.Env;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 *
 * @author geniuz
 */
public class FileWriterStream
{

    public FileWriterStream()
    {
        _wasWroteToFile = false;
    }

    public FileWriterStream(File file) throws FileNotFoundException
    {
        _wasWroteToFile = false;
        _fos = new FileOutputStream(file);
        _file = file;
    }

    public FileWriterStream(File file, boolean flag) throws FileNotFoundException
    {
        _wasWroteToFile = false;
        if(file != null)
        {
            _fos = new FileOutputStream(file, flag);
            _file = file;
        }
    }

    public final File getFile()
    {
        return _file;
    }

    public final void deleteFile()
    {
        try
        {
            if(_fos != null)
                _fos.close();
        }
        catch(IOException ioexception)
        {
            //LOG.error(ioexception);
        }
        if(_file != null)
            _file.delete();
    }

    public final void close() throws IOException
    {
        if(_fos != null)
            _fos.close();
    }

    public final void flush() throws IOException
    {
        if(_fos != null)
            _fos.flush();
    }

    public final void write(byte abyte0[]) throws IOException
    {
        if(!Env.getEnv().isTraceWindowParsing() && _fos != null)
        {
            _wasWroteToFile = true;
            _fos.write(abyte0);
        }
    }

    public final boolean isWroteToFile()
    {
        return _wasWroteToFile;
    }

    private boolean _wasWroteToFile;
    private FileOutputStream _fos;
    private File _file;
    //private static final Logger LOG = Logger.getLogger(com/alcatel/algo/out/outfilter/FileWriterStream);

}
